//检查指定对象内的所有easyui输入项
var EasyuiForm = {
    validate: function (target) {
        if ($.fn.validatebox) {
            var t = $(target);
            t.find('.validatebox-text:not(:disabled)').validatebox('validate');
            var invalidbox = t.find('.validatebox-invalid');
            invalidbox.filter(':not(:disabled):first').focus();
            return invalidbox.length;
        }
        return 0;
    },
    //清空指定对象内的所有easyui输入项
    clear: function (target) {
        $('input,select,textarea', target).each(function () {
            var t = this.type, tag = this.tagName.toLowerCase();
            if (t == 'text' || t == 'hidden' || t == 'password' || tag == 'textarea') {
                this.value = '';
            } else if (t == 'file') {
                var file = $(this);
                file.after(file.clone().val(''));
                file.remove();
            } else if (t == 'checkbox' || t == 'radio') {
                this.checked = false;
            } else if (tag == 'select') {
                this.selectedIndex = -1;
            }

        });
        if ($.fn.combo) $('.combo-f', target).combo('clear');
        if ($.fn.combobox) $('.combobox-f', target).combobox('clear');
        if ($.fn.combotree) $('.combotree-f', target).combotree('clear');
        if ($.fn.combogrid) $('.combogrid-f', target).combogrid('clear');
        this.validate(target);
    },

    reset: function (target) {
        var t = $(target);
        t.find('.validatebox-text').attr('readonly', true);
        if ($.fn.combo) { t.find('.combo-f').combo('reset'); }
        if ($.fn.combobox) { t.find('.combobox-f').combobox('reset'); }
        if ($.fn.combotree) { t.find('.combotree-f').combotree('reset'); }
        if ($.fn.combogrid) { t.find('.combogrid-f').combogrid('reset'); }
        if ($.fn.spinner) { t.find('.spinner-f').spinner('reset'); }
        if ($.fn.timespinner) { t.find('.timespinner-f').timespinner('reset'); }
        if ($.fn.numberbox) { t.find('.numberbox-f').numberbox('reset'); }
        if ($.fn.numberspinner) { t.find('.numberspinner-f').numberspinner('reset'); }
        this.validate(target);
    },
    disable: function (target) {
        var t = $(target);
        t.find('.validatebox-text').attr('readonly', true);
        t.find('input:checkbox').attr('disabled', true);
        if ($.fn.combo) { t.find('.combo-f').combo('disable'); }
        if ($.fn.combobox) { t.find('.combobox-f').combobox('disable'); }
        if ($.fn.combotree) { t.find('.combotree-f').combotree('disable'); }
        if ($.fn.combogrid) { t.find('.combogrid-f').combogrid('disable'); }
        if ($.fn.spinner) { t.find('.spinner-f').spinner('disable'); }
        if ($.fn.timespinner) { t.find('.timespinner-f').timespinner('disable'); }
        if ($.fn.numberbox) { t.find('.numberbox-f').numberbox('disable'); }
        if ($.fn.numberspinner) { t.find('.numberspinner-f').numberspinner('disable'); }
        this.validate(target);
    },

    isValidate: function (target,isvalid) {
        var t = $(target);
        t.find('.validatebox-text').validatebox({ isValidate: isvalid });
        this.validate(target);
    }
}